package com.yuelan.app.controller;

import com.yuelan.app.service.UserRentBillService;
import com.yuelan.common.core.web.controller.BaseController;
import com.yuelan.common.core.web.domain.AjaxResult;
import com.yuelan.common.core.web.page.PageDomain;
import com.yuelan.common.core.web.page.TableDataInfo;
import com.yuelan.common.log.annotation.Log;
import com.yuelan.common.log.enums.BusinessType;
import com.yuelan.common.security.annotation.RequiresPermissions;
import com.yuelan.system.api.RemoteOrderService;
import com.yuelan.system.api.domain.RentPayOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 租金信息
 * @Author: ZhaoYi
 * @date: 24-6-30 3:51
 */
@RestController
@RequestMapping("/rent")
public class UserRentController extends BaseController {

    @Autowired
    private UserRentBillService userRentBillService;
    @Autowired
    private RemoteOrderService remoteOrderService;


    @PostMapping
    @Log(title = "租金支付", businessType = BusinessType.INSERT)
    public AjaxResult payRent(@RequestBody RentPayOrder rentPayOrder) {
        return success(remoteOrderService.rentOrder(rentPayOrder));
    }


    @GetMapping("/list")
    @Log(title = "查看所有账单", businessType = BusinessType.QUERY)
    public TableDataInfo listBill(int pageNum, int pageSize) {
        return userRentBillService.billList(pageNum, pageSize);
    }


    @GetMapping("/{id}")
    @Log(title = "查看账单", businessType = BusinessType.QUERY)
    public AjaxResult view(@PathVariable Long id) {
        return success(userRentBillService.view(id));
    }


    @GetMapping("/expire")
    @Log(title = "逾期账单提醒", businessType = BusinessType.QUERY)
    public AjaxResult expireBill() {
        if (userRentBillService.expireBill()) {
            return error("您有逾期账单，请及时处理！");
        }
        return success();
    }


}
